package com.bungarus.busi;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by tang on 2018/11/18.
 */
public class Discharger {
    private static Map<String, DischargeQueue> queuesTobeDischarg;
    public static final String DISCHARGE_NAME_CLIENT = "client";
    public static final String DISCHARGE_NAME_GENERIC = "generic";

    static {
        queuesTobeDischarg = new HashMap<>(0);
        queuesTobeDischarg.put(DISCHARGE_NAME_CLIENT, new DischargeQueue(
                new ConcurrentHashMap<>()));
        queuesTobeDischarg.put(DISCHARGE_NAME_GENERIC, new DischargeQueue(
                new ConcurrentHashMap<>()));
    }

    public static DischargeQueue getQueueInstance() {
        return queuesTobeDischarg.get(DISCHARGE_NAME_GENERIC);
    }

    public static DischargeQueue getQueueInstance(String clusterTag) {
        return null == queuesTobeDischarg.get(clusterTag) ? getQueueInstance() : queuesTobeDischarg.get(clusterTag);
    }

    public static void discharge(String id) {
        discharge(id, DISCHARGE_NAME_GENERIC);
    }

    public static void discharge(String id, String clusterTag) {
        DischargeQueue queue = getQueueInstance(clusterTag);
        queue.removeFromQueue(Long.valueOf(id));
    }
}
